{template 'common/header'}
<div class="js-account" id="js-account-create" ng-controller="commonCreateAccountCtrl" ng-cloak>
	{if in_array($sign, array(ACCOUNT_TYPE_SIGN))}
	<div class="js-account-desc" ng-show="step == 'base_info'">
			<div class="js-account-desc_title">
				<span class="title-step">第一步</span>
				<span class="title-cont">设置公众号信息教程</span>
			</div>
			<div class="js-account-desc_content">
				<div class="content-title">操作说明:</div>
				<ul class="content-detail">
						<li class="index">登录微信公众平台 https://mp.weixin.qq.com/</li>
						<li class="index">找到菜单【设置与开发 > 基本配置 >公众号开发信息】</li>
						<li class="index">在【公众号开发信息】下找到AppID和AppSecret，如下图
								<div class="img" style="margin-top: 10px;"><img ng-src="./resource/images/update-guide-06.png" width="380" enlarge-pic></div>
						</li>
						<li class="index">将AppID和AppSecret信息填写到右侧输入框中</li>
						<li class="index">类型选择从微信公众平台找到菜单【公众号设置 > 账号详情 >公开信息】查看公众号类型及认证情况，如下图
								<div class="img" style="margin-top: 10px;"><img ng-src="./resource/images/update-guide-07.png" width="280" enlarge-pic></div>
						</li>
						<li class="index">公众号头像和二维码为非必填，完成点击“下一步”</li>
				</ul>
			</div>
	</div>
	<div class="js-account-desc" ng-show="step == 'account_modules'">
			<div class="js-account-desc_title">
					<span class="title-step">第二步</span>
					<span class="title-cont">设置权限教程</span>
			</div>
			<div class="js-account-desc_content">
					<div class="content-title">操作说明:</div>
					<ul class="content-detail">
							<li class="index" style="margin-bottom: 20px;">如果不选择主管理员，则默认创始人为该平台的主管理员</li>
							<li class="index" style="margin-bottom: 20px;">设置平台过期时间，默认不限</li>
							<li class="index" style="margin-bottom: 20px;">给公众号添加应用权限组：比如你事先添加了A和B两个应用为一个应用权限组，当前如果你分配应用权限组给了该平台，那么该平台只能使用A/B应用（非必选）</li>
							<li class="index" style="margin-bottom: 20px;">公众号附加应用：你可以给该平台附加除应用权限组以外的应用</li>
							<li class="index">完成后点击“完成设置”</li>
					</ul>
			</div>
	</div>
	{/if}
	<div class="js-account-create">
		{if $_W['iscontroller']}
		<ol class="breadcrumb we7-breadcrumb">
			<a href="{php echo url('account/manage/display')}"><i class="wi wi-back-circle"></i> </a>
			<li><a href="{php echo url('account/manage/display')}">平台列表</a></li>
			<li>新建{$account_all_type_sign[$sign]['title']}</li>
		</ol>
		{/if}
		<ul class="we7-step">
			<li ng-class="step == 'base_info' ? 'active' : ''"> <span class="content">1. 设置{$account_all_type_sign[$sign]['title']}信息</span> </li>
			{if !empty($_W['isfounder'])}
			<li ng-class="step == 'account_modules' ? 'active' : ''"> <span class="content">2. 设置权限</span></li>
			{/if}
			{if in_array($sign, array(ACCOUNT_TYPE_SIGN))}
			<li ng-class="step == 'account_help' ? 'active' : ''"><span class="content">{if empty($_W['isfounder'])}2{else}3{/if} 设置微信公众平台，并检测</span></li>
			{elseif in_array($sign, array(WXAPP_TYPE_SIGN, PHONEAPP_TYPE_SIGN, ALIAPP_TYPE_SIGN, BAIDUAPP_TYPE_SIGN, TOUTIAOAPP_TYPE_SIGN))}
			<li ng-class="step == 'account_version' ? 'active' : ''"><span class="content">{if empty($_W['isfounder'])}2{else}3{/if} 新建版本</span></li>
			{/if}
		</ul>
	
		<div ng-show="step == 'base_info'">
			<div class="we7-form">
				{if $sign == ACCOUNT_TYPE_SIGN}
				<div id="account_base_info">
					<div class="form-group required">
						<label for="" class="control-label col-sm-2">公众号名称:</label>
						<div class="form-controls col-sm-8">
							<input type="text" name="name" class="form-control" ng-model="account.name" autocomplete="off" placeholder="需要接入的公众号名称" />
							<!--<span class="help-block">填写公众号的账号名称</span>-->
						</div>
					</div>
					<div class="form-group required">
						<label for="" class="control-label col-sm-2">类型:</label>
						<div class="form-controls col-sm-8">
							<select name="level" ng-model="account.level">
									<option value="" selected disabled style="display: none">请选择公众号类型</option>
								<option value="1" ng-selected="account.level == 1">普通订阅号</option>
								<option value="2" ng-selected="account.level == 2">普通服务号</option>
								<option value="3" ng-selected="account.level == 3">认证订阅号</option>
								<option value="4" ng-selected="account.level == 4">认证服务号/认证媒体/政府订阅号</option>
							</select>
							<!--<span class="help-block">注意:即使公众平台显示为“未认证”, 但只要【公众号设置】/【账号详情】下【认证情况】显示资质审核通过, 即可认定为认证号.</span>-->
						</div>
					</div>
					<div class="form-group required">
						<label for="" class="control-label col-sm-2">AppId:</label>
						<div class="form-controls col-sm-8">
							<input type="text" name="key" class="form-control" ng-model="account.key" autocomplete="off" placeholder="公众号的AppId"/>
							<!--<span class="help-block">请填写微信公众平台后台的AppId</span>-->
						</div>
					</div>
					<div class="form-group required">
						<label for="" class="control-label col-sm-2">AppSecret:</label>
						<div class="form-controls col-sm-8">
							<input type="text" name="secret" class="form-control" ng-model="account.secret" autocomplete="off" placeholder="公众号的AppSecret"/>
							<!--<span class="help-block">请填写微信公众平台后台的AppSecret</span>-->
						</div>
					</div>
					<div class="form-group">
						<label for="" class="control-label col-sm-2">公众号头像</label>
						<div class="form-controls col-sm-8">
							<div class="input-more we7-input-img" ng-class="{'active': account.headimg}">
								<img ng-src="{{account.headimg}}" width="150px" ng-if="account.headimg" ng-style="{'height': 'auto'}">
								<a href="javascript:;" class="input-addon" ng-click="uploadMultiImage('headimg')" ng-hide="account.headimg"><span>+</span></a>
								<input type="text" name="headimg" ng-model="account.headimg" ng-style="{'display' : 'none'}">
								<div class="cover-dark">
									<a href="javascript:;" class="cut" ng-click="uploadMultiImage('headimg')">更换</a>
									<a href="javascript:;" class="del" ng-click="delMultiImage('headimg')"><i class="fa fa-times text-danger"></i></a>
								</div>
							</div>
							<span class="help-block"></span>
						</div>
					</div>
					<div class="form-group">
						<label for="" class="control-label col-sm-2">公众号二维码</label>
						<div class="form-controls col-sm-8">
							<div class="input-more we7-input-img" ng-class="{'active': account.qrcode}">
								<img ng-src="{{account.qrcode}}" width="150px" ng-if="account.qrcode" ng-style="{'height': 'auto'}">
								<a href="javascript:;" class="input-addon" ng-click="uploadMultiImage('qrcode')" ng-hide="account.qrcode"><span>+</span></a>
								<input type="text" name="qrcode" ng-model="account.qrcode" ng-style="{'display' : 'none'}">
								<div class="cover-dark">
									<a href="javascript:;" class="cut" ng-click="uploadMultiImage('qrcode')">更换</a>
									<a href="javascript:;" class="del" ng-click="delMultiImage('qrcode')"><i class="fa fa-times text-danger"></i></a>
								</div>
							</div>
							<span class="help-block"></span>
						</div>
					</div>
				</div>
				{elseif $sign == WEBAPP_TYPE_SIGN}
				<div id="webapp_base_info">
					<div id="js-webapp">
						<div class="form-group required">
							<label for="" class="control-label col-sm-2">PC名称</label>
							<div class="form-controls col-sm-8">
								<input type="text" name="name" ng-model="account.name" class="form-control" required autocomplete="off" />
								<span class="help-block">填写PC名称</span>
							</div>
						</div>
						<div class="form-group">
							<label for="" class="control-label col-sm-2">描述</label>
							<div class="form-controls col-sm-8">
								<textarea class="form-control" name="description" ng-model="account.description" style="height: 80px;"></textarea>
								<span class="help-block">用于说明此PC的功能及用途。</span>
							</div>
						</div>
					</div>
				</div>
				{elseif $sign == PHONEAPP_TYPE_SIGN}
				<div id="phoneapp_base_info">
					<div id="js-phoneapp">
						<div class="form-group required">
							<label class="control-label col-sm-2">APP名称</label>
							<div class="form-controls col-sm-8">
								<input type="text" name="name" class="form-control" ng-model="account.name" placeholder="APP名称" required>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-sm-2">APP描述</label>
							<div class="form-controls col-sm-8">
								<input type="text" name="description" ng-model="account.description" class="form-control" placeholder="版本描述">
							</div>
						</div>
					</div>
				</div>
				{elseif in_array($sign, array(WXAPP_TYPE_SIGN, ALIAPP_TYPE_SIGN, BAIDUAPP_TYPE_SIGN, TOUTIAOAPP_TYPE_SIGN))}
				<div id="miniapp_base_info">
					<div class="form-defalut we7-form">
						<div class="form-group required">
							<label for="" class="control-label col-sm-2">{$sign_title}名称</label>
							<div class="form-controls col-sm-10">
								<input type="text" name="name" ng-model="account.name" class="form-control wxapp-name" placeholder="{if !empty($type)}{$account_all_type[$type]['title']}{/if}名称" required>
							</div>
						</div>
						<div class="form-group">
							<label for="" class="control-label col-sm-2">{$sign_title}描述</label>
							<div class="form-controls col-sm-10">
								<input type="text" name="description" ng-model="account.description" class="form-control wxapp-name" placeholder="版本描述">
							</div>
						</div>
						<div class="form-group" ng-if="account.sign == 'wxapp'">
							<label for="" class="control-label col-sm-2">原始ID</label>
							<div class="form-controls col-sm-10">
								<input type="text" name="original" ng-model="account.original" value="" class="form-control wxapp-name" placeholder="原始ID">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="control-label col-sm-2">AppId</label>
							<div class="form-controls col-sm-10">
								<input type="text" name="appid" ng-model="account.appid" class="form-control wxapp-name" placeholder="AppId">
							</div>
						</div>
						<div class="form-group" ng-if="account.sign == 'baiduapp'">
							<label for="" class="control-label col-sm-2">AppKey</label>
							<div class="form-controls col-sm-10">
								<input type="text" name="key" ng-model="account.key" class="form-control wxapp-name" placeholder="AppKey">
							</div>
						</div>
						<div class="form-group" ng-if="account.sign == 'wxapp' || account.sign == 'baiduapp' || account.sign == 'toutiaoapp'">
							<label for="" class="control-label col-sm-2">AppSecret</label>
							<div class="form-controls col-sm-10">
								<input type="text" name="secret" ng-model="account.secret" class="form-control wxapp-name" placeholder="AppSecret">
							</div>
						</div>
						<div class="form-group" ng-hide="newversion">
							<label for="" class="control-label col-sm-2">头像</label>
							<div class="form-controls col-sm-8">
								<div class="input-more we7-input-img" ng-class="{'active': account.headimg}">
									<img ng-src="{{account.headimg}}" width="150px" ng-if="account.headimg" ng-style="{'height': 'auto'}">
									<a href="javascript:;" class="input-addon" ng-click="uploadMultiImage('headimg')" ng-hide="account.headimg"><span>+</span></a>
									<input type="text" name="headimg" ng-model="account.headimg" class="hidden">
									<div class="cover-dark">
										<a href="javascript:;" class="cut" ng-click="uploadMultiImage('headimg')">更换</a>
										<a href="javascript:;" class="del" ng-click="delMultiImage('headimg')"><i class="fa fa-times text-danger"></i></a>
									</div>
								</div>
								<span class="help-block"></span>
							</div>
						</div>
						<div class="form-group" ng-hide="newversion">
							<label for="" class="control-label col-sm-2">二维码</label>
							<div class="form-controls col-sm-8">
								<div class="input-more we7-input-img" ng-class="{'active': account.qrcode}">
									<img ng-src="{{account.qrcode}}" width="150px" ng-if="account.qrcode" ng-style="{'height': 'auto'}">
									<a href="javascript:;" class="input-addon" ng-click="uploadMultiImage('qrcode')" ng-hide="account.qrcode"><span>+</span></a>
									<input type="text" name="qrcode" ng-model="account.qrcode"  class="hidden">
									<div class="cover-dark">
										<a href="javascript:;" class="cut" ng-click="uploadMultiImage('qrcode')">更换</a>
										<a href="javascript:;" class="del" ng-click="delMultiImage('qrcode')"><i class="fa fa-times text-danger"></i></a>
									</div>
								</div>
								<span class="help-block"></span>
							</div>
						</div>
					</div>
				</div>
				{/if}
				<div class="col-sm-offset-2">
					<input type="submit" name="submit" value="下一步" class="btn btn-primary btn-submit" ng-click="submitBaseinfo()"/>
				</div>
			</div>
		</div>
	
		<div ng-show="step == 'account_modules'">
			<div class="we7-form account-create-step">
				<div class="we7-page-alert">
					如果不选择主管理员，则默认创始人为该账号的主管理员
				</div>
				<div class="form-group">
					<div class="control-label col-sm-2">主管理员:</div>
					<div class="form-controls col-sm-8">
						<div class="input-group">
							<input type="hidden" name="uid" value="" id="manager">
							<input type="text" class="form-control" ng-model="owner.username" id="showname">
							<span class="input-group-btn">
								<a class="btn btn-default" href="javascript:;" ng-click="selectOwner($event)">选择管理员</a>
							</span>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label for="" class="control-label col-sm-2">平台过期时间:</label>
					<div class="form-controls col-sm-8">
						<div class="input-group">
							<span class="input-group-btn">
								<select name="" class="select-endtime" id="" ng-model="owner.endtime" ng-change="changeEndtime()" style="width: 75px">
									<option value="1">设置</option>
									<option value="0" >不限时间</option>
								</select>
							</span>
							<div ng-show="owner.endtime == 1">
								{php echo tpl_form_field_date('endtime', 0);}
							</div>
						</div>
						<span class="help-block">平台有效期默认与主管理员一致，修改日期不可超过主管理员有效期的最大期限。未设置主管理员时，创始人默认为主管理员</span>
					</div>
				</div>
				<!--应用权限组-->
				<div class="form-group">
						<label for="" class="control-label col-sm-2">{$sign_title}附加应用权限组:</label>
						<div class="form-controls col-sm-8">
								<div class="we7-group-show" ng-repeat="extend in groupAll.groups" ng-if="extend.checked == 1">
										<div class="name">
									{{extend.name}}
								</div>
								<div class="group-app-list">
									<div class="group-app-item" ng-repeat="module in extend.modules_all">
										<img src="{{module.logo}}" class="module-img" alt="">
										<div class="info">
											<div class="title text-over">
												{{module.title}}
											</div>
											<div class="type-list">
												<i ng-class="itme.icon" ng-repeat="itme in module.group_support | moduleInfo" ></i>
											</div>
										</div>
									</div>
									<div class="group-app-item" ng-repeat="module in extend.templates">
										<img src="{{module.logo}}" class="template-img" alt="">
										<div class="info">
											<div class="title">
												{{module.title}}
											</div>
											<div class="type-list">
												<i class="wi wi-template"></i>
											</div>
										</div>
									</div>
								</div>
								<!--<a class="action"></a>-->
								<a href="" class="remove" ng-click="extend.checked = 0"><i class="wi wi-error"></i></a>
								</div>
						
						<we7-modal-app module-list="groupAll" multiple="true" ng-init="loadGroups()" on-confirm="groupConfirm()">
								<div class="add-new-block" >
									<i class="wi wi-plus"></i> 添加应用权限组
								</div>
							</we7-modal-app>
					</div>
				</div>
				<!--附加应用-->
				<div class="form-group">
						<label for="" class="control-label col-sm-2">{$sign_title}附加应用:</label>
						<div class="group-post-mudules form-controls col-sm-8">
						<div class="module-item" ng-repeat="module in modulesAll.modules" ng-if="module.checked == 1">
							<div class="logo">
								<img ng-src="{{module.logo}}" alt="">
							</div>
							<div class="info">
								<div ng-bind="module.title" class="title text-over">1213</div>
								<div class="icon">
									<i class="{{module.support | moduleInfo:'icon'}}"></i>
								</div>
							</div>
							<div class="delete">
								<i class="wi wi-error" ng-click="module.checked = 0"></i>
							</div>
						</div>
						<div class="module-item" ng-repeat="template in modulesAll.templates"  ng-if="template.checked == 1">
							<div class="logo">
								<img ng-src="{{template.logo}}" alt="">
							</div>
							<div class="info">
								<div class="name text-over" ng-bind="template.title">1213</div>
								<div class="icon">
									<i class="wi wi-template"></i>
								</div>
							</div>
							<div class="delete">
								<i class="wi wi-error" ng-click="template.checked = 0"></i>
							</div>
						</div>
						<we7-modal-app module-list="modulesAll" title="'添加应用'" multiple="true">
							<div class="module-item add" >
								<i class="wi wi-plus"></i> 添加应用
							</div>
						</we7-modal-app>
					</div>
				</div>
				
				<div class="col-sm-offset-2 form-controls col-sm-8" ng-show="groupAll.groups">
					<div class="we7-header" ng-show="owner.username">
						主管理员应用/模板权限
					</div>
					<div class="we7-group-show" ng-if="owner.modules">
						<input class="hidden" type="checkbox" name="package[]" checked ng-value="package">
						<div class="name">
							主管理员权限
						</div>
						<div class="group-app-list">
							<div class="group-app-item" ng-repeat="module in owner.modules">
								<img src="{{module.logo}}" class="module-img" alt="">
								<div class="info">
									<div class="title text-over">
										{{module.title}}
									</div>
									<div class="type-list">
										<i class="wi wi-{$account['type_sign']}"></i>
									</div>
								</div>
							</div>
							<div class="group-app-item" ng-if="owner.modules.length < 1">暂无应用</div>
	
							<div class="group-app-item" ng-repeat="module in unigroups[package].templates">
								<img src="{{module.logo}}" class="template-img" alt="">
								<div class="info">
									<div class="title">
										{{module.title}}
									</div>
									<div class="type-list">
										<i class="wi wi-template"></i>
									</div>
								</div>
							</div>
						</div>
						<a class="action"></a>
					</div>
				</div>
				<div class="clearfix"></div>
				<div class="col-sm-offset-2">
					<input type="button" value="上一步" ng-click="step = 'base_info'" class="btn btn-primary btn-submit"/>
					<!--<input type="button" ng-click="submitAccountModules()" value="{if in_array($sign, array(WEBAPP_TYPE_SIGN))}完成{else}下一步{/if}" class="btn btn-primary btn-submit"/>-->
					<input type="button" ng-click="submitAccountModules()" value="完成设置" class="btn btn-primary btn-submit"/>
				</div>
			</div>
		</div>
	
		<div ng-show="step == 'account_version'">
			<div class="wxapp-content tab-content" style="width: 100%;">
				<div id="select">
					<div class="form-defalut we7-form">
						<div class="form-group">
							<label for="" class="control-label col-sm-2">{$sign_title}名称</label>
							<div class="form-controls col-sm-10">
								<input type="text" name="name" ng-model="account.name" class="form-control wxapp-name" disabled>
							</div>
						</div>
						<div class="form-group">
							<label for="" class="control-label col-sm-2">版本描述</label>
							<div class="form-controls col-sm-10">
								<input type="text" name="description" ng-model="account.version_description" class="form-control wxapp-name">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="control-label col-sm-2">版本号</label>
							<div class="form-controls col-sm-10">
								<input type="text" name="version" ng-model="account.version" class="form-control wxapp-name" placeholder="版本号，只能是数字、点，数字最多两位，例如 1.01 / 1.0.1">
							</div>
						</div>
						<div class="form-group">
							<input type="hidden" name="modules" value="">
							<label class="control-label col-sm-2">添加应用</label>
							<div class="form-controls col-sm-10">
								<ul class="app-list" ng-click="resourceModule()">
									<div class="app-info" ng-show="version_module.title">
										<img ng-src="{{version_module.icon}}" />
										<p>{{version_module.title}}</p>
									</div>
									<li class="select select-more"></li>
								</ul>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="col-sm-offset-2">
				{if !empty($_W['isfounder'])}
				<input type="button" value="上一步" ng-click="step = 'account_modules'" class="btn btn-primary btn-submit"/>
				{else}
				<input type="button" value="上一步" ng-click="step = 'base_info'" class="btn btn-primary btn-submit"/>
				{/if}
				<input type="submit" value="生成版本" ng-click="submitAccountVersion()" class="btn btn-primary btn-submit"/>
			</div>
		</div>
	</div>
	<!--遮罩层-->
	<div class="mask" close-pic>
			<div class="mask-box"></div>
			<div class="big-pic-wrap">
					<img src="" alt="" class="bigPic" />
			</div>
	</div>
</div>

<script type="text/javascript">
	angular.module('accountApp').value('config', {
		token: "{$_W['token']}",
		sign: "{$sign}",
		sign_title: "{$sign_title}",
		uid: "{$_W['uid']}",
		isfounder: {php echo intval($_W['isfounder'])},
		//设置权限
		unigroups: {php echo !empty($unigroups) ? json_encode($unigroups) : 'null'},
		modules: {php echo !empty($modules) ? json_encode($modules) : 'null'},
		links: {
			userinfo: "{php echo url('account/create/get_user_info', array('sign' => $sign))}",
			check_params: "{php echo url('account/create/check_params')}",
			save_account: "{php echo url('account/create/save_account')}",
			load_groups: "{php echo url('account/create/load_groups', array('sign' => $sign))}",
		}
	});
	angular.module('accountApp').directive('enlargePic',function(){
		return{
			restrict: "AE",
			link: function(scope,elem){
				elem.bind('click',function($event){
					var img = $event.srcElement || $event.target;
					angular.element(document.querySelector(".mask"))[0].style.display = "block";
					angular.element(document.querySelector(".bigPic"))[0].src = img.src;
				})
			}
		}
	})
	.directive('closePic',function(){
		return{
			restrict: "AE",
				link: function(scope,elem){
					elem.bind('click',function($event){
						angular.element(document.querySelector(".mask"))[0].style.display = "none";
					})
				}
		}
	});
	angular.bootstrap($('#js-account-create'),['accountApp']);
</script>
<style lang="scss">
.js-account{
		width: 100%;
		display: flex;
}
.js-account-desc{
		width: 30%;
		height: auto;
		display: inline-block;
		margin-right: 60px;
		background-color: #F0F3FA;
		padding: 30px 15px;
}
.js-account-desc_title{
		font-size: 18px;
		text-align: center;
		margin-bottom: 10px;
}
.title-step{
		color: #3296fa;
}
.title-cont{
		font-weight: bold;
}
.js-account-desc_content{
		font-size: 14px;
}
.content-title{
		margin-bottom: 10px;
}
.content-detail{
		counter-reset: index;
		padding: 5px 0px;
		line-height: 20px;
}
.content-detail .index{
		padding-left: 25px;
		position: relative;
		margin-bottom: 10px;
}
.content-detail .index:before{
		content: counter(index);
		counter-increment: index;
		display: inline-block;
		width: 20px;
		height: 20px;
		color: #fff;
		font-size: 12px;
		text-align: center;
		line-height: 20px;
		position: absolute;
		left: 0;
		top: 0;
		border-radius: 50%;
		background-color: #3296fa;
}
.js-account-create{
		flex: 1;
		display: inline-block;
}
.mask{
		display: none;
		background: none;
}
.mask-box{
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: 99;
		opacity: 0.5;
		background-color: #000;
}
.big-pic-wrap{
		position: fixed;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		z-index: 100;
}
.nice-select{
		z-index: 1 !important;
}
.we7-group-show .name {
		flex: 0 0 120px !important;
}
.we7-group-show .group-app-list .group-app-item {
		width: 33% !important;
}
</style>
{template 'common/footer'}
